import 'package:flutter/widgets.dart';
import 'package:get/get.dart';
import 'package:vape_xe/services/services.dart';
import 'package:vape_xe/utils/utils.dart';

class ScanDialogController extends GetxController {
  /// 响应式成员变量
  final inviteCode = ''.obs;
  final params = <String, dynamic>{}.obs;

  ScanDialogController(Map<String, dynamic> aa) {
    params.value = aa;
  }

  void noExtra() {
    toast('Success');
    EventService.to.sendMessage(EventService.EventRefresh);
    Navigator.pop(Get.context!);
  }

  Future<void> getExtra() async {
    if (inviteCode.value.isEmpty) return;
    Loading.show();
    Request().post('/userVape/confirmInviteCode', {
      'inviteCode': inviteCode.value,
      'type': params['type'],
      'targetId': params['targetId'],
    }).then((result) {
      toast('Success');
      EventService.to.sendMessage(EventService.EventRefresh);
      Navigator.pop(Get.context!);
    });
  }
}
